<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div id="app">
            <p>性别: {{sex | formatterSex}}</p>
        </div>
        <div id="vm">
            <p>性别: {{sex | formatterSex}}</p>
        </div>
        <script src="../vue.js"></script>
        <script>
            // Vue.filter: 全局注册过滤器
            Vue.filter('formatterSex', function (val) {
                return val === 1 ? '男' : val === 2 ? '女' : '未知';
            });
            new Vue({
                el: '#app',
                data() {
                    return {
                        sex: 2, // 3 未知
                    };
                },
            });
            new Vue({
                el: '#vm',
                data() {
                    return {
                        sex: 1,
                    };
                },
            });
        </script>
    </body>
</html>
